<template>
  <view class="behavior_llist_box">
    <view class="date_container">
      <DateType
        :pickerValue="pickerValue"
        @updatePickerValue="updatePickerValue"
      />
    </view>
    <view v-if="dataList.length == 0">
      <Empty />
    </view>
    <scroll-view
      class="scroll-view"
      :scroll-y="isScroll"
      upper-threshold="0"
      :refresher-enabled="false"
      refresher-default-style="white"
      @scrolltoupper="refresherrefresh"
      lower-threshold="120"
      @scrolltolower="getBehaviorData(pickerValue, '加载更多')"
    >
      <view class="list_box" v-if="dataList.length > 0">
        <view class="manage_content bc_fff" v-if="type == 2">
          <view class="single_content w100 height_41 br_4 fz_11 fc_333">
            <view class="pl_12 single_left box width_60"> 店长 </view>
            <view class="single"> 分享 </view>
            <view class="single"> 收藏 </view>
            <view class="single"> 购买 </view>
            <view class="single"> 加购 </view>
            <view class="single"> 浏览 </view>
            <view class="single"> 邀请注册 </view>
          </view>
          <template v-for="(item, index) in dataList">
            <view
              class="list single_content w100 height_41 br_4 fz_11 fc_333"
              :key="index"
            >
              <view class="pl_12 single_left box width_60">
                {{ item.username }}
              </view>
              <view class="single"> {{ item.shareNum }}次 </view>
              <view class="single"> {{ item.collectNum }}次 </view>
              <view class="single"> {{ item.purchaseNum }}次 </view>
              <view class="single"> {{ item.addNum }}次 </view>
              <view class="single"> {{ item.lookNum }}次 </view>
              <view class="single"> {{ item.inviteNum }}次 </view>
            </view>
          </template>
        </view>
        <view class="manage_content bc_fff" v-if="type == 1">
          <view class="single_content w100 height_41 br_4 fz_11 fc_333">
            <view class="pl_12 single_left box width_60"> 导购员 </view>
            <view class="single"> 分享 </view>
            <view class="single"> 收藏 </view>
            <view class="single"> 购买 </view>
            <view class="single"> 加购 </view>
            <view class="single"> 浏览 </view>
            <view class="single"> 邀请注册 </view>
          </view>
          <template v-for="(item, index) in dataList">
            <view
              class="list single_content w100 height_41 br_4 fz_11 fc_333"
              :key="index"
            >
              <view class="pl_12 single_left box width_60">
                {{ item.username }}
              </view>
              <view class="single"> {{ item.shareNum }}次 </view>
              <view class="single"> {{ item.collectNum }}次 </view>
              <view class="single"> {{ item.purchaseNum }}次 </view>
              <view class="single"> {{ item.addNum }}次 </view>
              <view class="single"> {{ item.lookNum }}次 </view>
              <view class="single"> {{ item.inviteNum }}次 </view>
            </view>
          </template>
        </view>
        <view class="manage_content bc_fff" v-if="type == 3">
          <view class="single_content w100 height_41 br_4 fz_11 fc_333">
            <view class="pl_12 single_left box width_75"> 商品名称 </view>
            <view class="single"> 分享 </view>
            <view class="single"> 收藏 </view>
            <view class="single"> 购买 </view>
            <view class="single"> 加购 </view>
            <view class="single"> 浏览 </view>
          </view>
          <template v-for="(item, index) in dataList">
            <view
              class="list single_content w100 height_41 br_4 fz_11 fc_333"
              :key="index"
            >
              <view class="pl_12 single_left box width_75">
                {{ item.username }}
              </view>
              <view class="single"> {{ item.shareNum || 0 }}次 </view>
              <view class="single"> {{ item.collectNum || 0 }}次 </view>
              <view class="single"> {{ item.purchaseNum || 0 }}次 </view>
              <view class="single"> {{ item.addNum || 0 }}次 </view>
              <view class="single"> {{ item.lookNum || 0 }}次 </view>
            </view>
          </template>
        </view>
      </view>
    </scroll-view>
  </view>
</template>

<script>
import Empty from "./merchant/components/empty.vue";
import DateType from "../index/radar/components/DateType.vue";
import api from "@/service/config/api";
export default {
  components: {
    DateType,
    Empty,
  },
  props: {
    userType: {
      default: 4,
      type: Number,
    },
    behaviorData: {
      default: {},
      type: Object,
    },
    managerList: {
      default: [],
      type: Array,
    },
    guideList: {
      default: [],
      type: Array,
    },
    goodsList: {
      default: [],
      type: Array,
    },
  },
  data() {
    return {
      isScroll: true,
      type: 1,
      pickerValue: {
        type: 1,
        label: "今日",
        startTime: "",
        endTime: "",
      },
      total: 0,
      current: 1,
      size: 20,
      dataList: [],
    };
  },
  wtach: {
    pickerValue: {
      handler(newValue, oldValue) {
        console.log("请求参数");
        console.log("新的请求");
        console.log(newValue);
        console.log(oldValue);
        // if (newValue.type != oldValue.type) {
        // 	this.getBehaviorData()
        // }
      },
      deep: true,
    },
  },
  onLoad(options) {
    console.log("上个月面的菜蔬");
    console.log(options);
    this.type = options.type;
    console.log("获取道德参数");
    console.log(this.type);
    this.getBehaviorData(this.pickerValue);
  },
  methods: {
    // 下拉刷新
    refresherrefresh() {
      console.log("下拉刷新");
      this.current = 1;
      this.getBehaviorData(this.pickerValue);
    },
    updatePickerValue(value) {
      console.log("父组件的值");
      console.log(value);
      if (value.type == 5) {
        if (new Date(value.startTime) > new Date(value.endTime)) {
          uni.showToast({
            title: "开始时间不能大于结束时间",
            icon: "none",
            duration: 1500,
          });
          return;
        }
        if (
          value.startTime &&
          value.endTime &&
          (value.startTime != this.pickerValue.startTime ||
            value.endTime != this.pickerValue.endTime)
        ) {
          this.current = 1;
          this.getBehaviorData(value);
        }
      } else if (value.type != this.pickerValue.type) {
        this.current = 1;
        this.getBehaviorData(value);
      }
      this.pickerValue = value;
      // if (value.type != this.pickerValue.type) {
      // 	this.pickerValue = value
      // 	this.getBehaviorData()
      // }

      console.log(this.pickerValue);
    },
    getBehaviorData(value, type) {
      console.log("请求数据据", type);
      const that = this;
      api
        .post("/user/api/radar/behaviorPageData", {
          current: that.current,
          size: that.size,
          dateType: value.type != 5 ? value.type : "",
          dataType: Number(that.type),
          orderType: 1,
          beginTime: value.startTime,
          endTime: value.endTime,
        })
        .then((res) => {
          if (res && res.code == 0) {
            const data = res.data.records;
            this.total = res.data.total;
            if (this.current == 1) {
              this.dataList = [];
            }
            if (this.dataList.length < this.total) {
              this.dataList = this.dataList.concat(data);
              this.current++;
              console.log("获取到的数据");
              console.log(this.dataList);
            }
          }
          // console.log("请求结果")
          // console.log(res)
          // this.dataList = res.data.records
        });
      // uni.navigateTo({
      // 	url:`/pages/radar/behavior_list?type=${type}`
      // })
    },
  },
};
</script>

<style lang="scss" scoped>
.scroll-view {
  height: 100%;
}
.behavior_llist_box {
	height: 100vh;
  .date_container {
  }

  .list_box {
    margin-top: 20rpx;

    .manage_content {
      .single_content {
        @include flex_box(row, nowrap, space-between, center);
        border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);

        .single_left {
          white-space: nowrap;
          text-overflow: ellipsis;
          overflow: hidden;
        }

        .single {
          white-space: nowrap;
          @include set_padding(0rpx, 12rpx);
        }
      }

      .list {
        color: #86909c;
      }
    }
  }
}
</style>
